package com.qqonline.mpf;

import java.util.List;

import com.qqonline.conmon.AsyncImageTask;
import com.qqonline.domain.MpfPicture;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class ImageAdapter extends BaseAdapter {
	private List<MpfPicture> picList;
	private PicPlayActivity activity;
	public LayoutInflater mInflater;
	private Display display;
	public ImageAdapter(List<MpfPicture> picList,PicPlayActivity pactivity,Display display) {
		// TODO Auto-generated constructor stub
		this.picList = picList;
		this.display=display;
		this.activity = pactivity;
		this.mInflater  = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return picList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return picList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
        if (convertView != null) {
                view = convertView;
        } else {
                view = mInflater.inflate(R.layout.playphoneitem, null);
        }
        ImageView img= (ImageView) view.findViewById(R.id.playImage);        
		img.setScaleType(ScaleType.FIT_CENTER);//centerInside
        String phoneImage = picList.get(position).getPicUrl();
        AsyncImageTask imageTask = new AsyncImageTask(img,activity,display);
        imageTask.execute(phoneImage);
		return view;
	}

}
